<template>
  <div
    id="flipdown"
    class="flipdown"
  />
</template>

<script>
import { FlipDown } from '../../utils/flipdown';

export default {
  name: 'FlipDown',
  props: ['countdown', 'onEnd', 'id'],
  data() {
    return {};
  },
  computed: {},
  mounted: function () {
    console.log(this.countdown);
    const flip = new FlipDown((new Date().getTime() / 1000) + this.countdown);
    flip.start().ifEnded(() => this.onEnd(this.id));
  },
  methods: {}
};
</script>

<style lang="scss">
  /* Rotor tops */
  .flipdown .rotor,
  .flipdown .rotor-top,
  .flipdown .rotor-leaf-front {
    color: #FFFFFF;
    background-color: #151515;
  }
  /* Rotor bottoms */
  .flipdown .rotor-bottom,
  .flipdown .rotor-leaf-rear {
    color: #EFEFEF;
    background-color: #202020;
  }

  .flipdown {
    overflow: visible;
    width: 510px;
    height: 80px;
    font-family: sans-serif;
    font-weight: bold;
    display: flex;
    flex-direction: row;
    justify-content: left;
    align-items: baseline;

    .rotor-group {
      position: relative;
      float: left;
      padding-right: 30px;

      /* 暴力隐藏前两位。。。 */
      &:nth-last-child(n+3) {
        display: none;
      }
    }

    .rotor-group-heading:before {
      display: block;
      height: 30px;
      line-height: 30px;
      text-align: center;
    }

    .rotor {
      position: relative;
      float: left;
      width: 50px;
      height: 80px;
      margin: 0px 5px 0px 0px;
      border-radius: 4px;
      font-size: 50px;
      text-align: center;
      perspective: 200px;

      &:last-child {
        margin-right: 0;
      }

      &:after {
        content: '';
        z-index: 2;
        position: absolute;
        bottom: 0px;
        left: 0px;
        width: 50px;
        height: 40px;
        border-radius: 0px 0px 4px 4px;
        border-top: solid 1px #151515;
      }
    }

    .rotor-top,
    .rotor-bottom {
      overflow: hidden;
      position: absolute;
      width: 50px;
      height: 40px;
    }

    .rotor-leaf {
      z-index: 1;
      position: absolute;
      width: 50px;
      height: 80px;
      transform-style: preserve-3d;
      transition: transform 0s;
    }

    .rotor-leaf.flipped {
      transform: rotateX(-180deg);
      transition: all 0.5s ease-in-out;
    }

    .rotor-leaf-front,
    .rotor-leaf-rear {
      overflow: hidden;
      position: absolute;
      width: 50px;
      height: 40px;
      margin: 0;
      transform: rotateX(0deg);
      backface-visibility: hidden;
      -webkit-backface-visibility: hidden;
    }

    .rotor-leaf-front {
      line-height: 80px;
      border-radius: 4px 4px 0px 0px;
    }
    .rotor-leaf-rear {
      line-height: 0px;
      border-radius: 0px 0px 4px 4px;
      transform: rotateX(-180deg);
    }
    .rotor-top {
      line-height: 80px;
      border-radius: 4px 4px 0px 0px;
    }
    .rotor-bottom {
      bottom: 0;
      line-height: 0px;
      border-radius: 0px 0px 4px 4px;
    }

    .rotor-group:nth-child(3) .rotor-group-heading:before {
      content: '分';
      position: absolute;
      bottom: 3px;
      right: 0;
      font-size: 18px;
      color: #9B9EA0;
    }

    .rotor-group:nth-child(4) .rotor-group-heading:before {
      content: '秒';
      position: absolute;
      bottom: 3px;
      right: 0;
      font-size: 18px;
      color: #9B9EA0;
    }
  }

</style>
